<?php

use yii\db\Migration;
use yii\db\Schema;

class m170120_103001_CREATE_TABLE_ORDER_ROOM_CUSTOMER extends Migration
{
    public function up()
    {

        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        // 产品线路信息
        $this->createTable('order_room_customer', [
            "id" =>          Schema::TYPE_PK,
            "order_id" =>    Schema::TYPE_INTEGER.    "(11) NOT NULL  COMMENT '订单编号'",
            "order_room_id"=>Schema::TYPE_INTEGER.    "(11) NOT NULL  COMMENT '对应的房间号'",
            "customer_id"=>  Schema::TYPE_INTEGER.    "(11) NULL  COMMENT '客户编号'",
            "price" =>       Schema::TYPE_DECIMAL.    "(10,2) DEFAULT NULL COMMENT '实际金额'",
            "status" =>      Schema::TYPE_INTEGER.    "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>     Schema::TYPE_INTEGER.    "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" =>  Schema::TYPE_DATETIME.   " NULL",
            "updated_at" =>  Schema::TYPE_TIMESTAMP.  " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);
        $this->createIndex("order_room_customer_order_id", "order_room_customer", "order_id");
        $this->createIndex("order_room_customer_order_room_id", "order_room_customer", "order_room_id");

        $this->dropColumn('{{order_room}}', 'price');
        $this->dropColumn('{{order_room}}', 'customer_id');

    }

    public function down()
    {
        echo "m170120_103001_CREATE_TABLE_ORDER_ROOM_CUSTOMER cannot be reverted.\n";

        return false;
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
